<%@ page language="java" contentType="text/html; charset=ISO-8859-1" import="java.sql.*"
    pageEncoding="ISO-8859-1"%>
 <%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 <html>
<head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>ADG-Add Template</title>
<link  href="css/style.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.style1 {
	color: #000000;font-size: 16px;
	font-family: Georgia, "Times New Roman", Times, serif;
}
#Layer1 {
	position:absolute;
	width:200px;
	height:32px;
	z-index:1;
	left: 299px;
	top: 82px;
}
.style4 {font-family: "Monotype Corsiva"}
.style5 {
	font-family: "Monotype Corsiva";
	font-size: 26px;
	color: #333333;
}
#Layer2 {
	position:absolute;
	width:779px;
	height:34px;
	z-index:1;
	top: 129px;
	left: 4px;
}
#Layer3 {
	position:absolute;
	width:124px;
	height:185px;
	z-index:1;
	left: 59px;
	top: 220px;
}
.style6 {font-family: "Monotype Corsiva"; color: #333333; font-size: 48px;}
#Layer4 {
	position:absolute;
	width:92px;
	height:31px;
	z-index:2;
	left: 1044px;
	top: 127px;
}
.style7 {
	font-family: "Times New Roman", Times, serif;
	font-size: 20px;
}
.msgstyle {color: red;font-size: 22px;
	font-family: Georgia, "Times New Roman", Times, serif;}
#msgLayer {
	position:absolute;
	text-align:center;
	width:50%;
	height:56px;
	z-index:4;
	left: 25%;
	top: 150px;
}
-->
</style>

</head>
<body>
<jsp:include page="head.jsp" />
<SCRIPT language="javascript"> 
var i=0,j=0;
var count=0;
var a=new Array(10);
var vals=null;

function add()
	{
	count=document.form1.uitype1.options.length;
	for(j=0;j<document.form1.uitype1.options.length;j++)
	{
	a[j]=document.form1.uitype1.options[j].value;	
	}
	
	
	 var tbl = document.getElementById('multipleRangeTable');   // ID of table
     var lastRow = tbl.rows.length;
    
     var rowNumber = lastRow + 1;
     var row = tbl.insertRow(lastRow);  
     
     // cell 1
     var minCell = row.insertCell(0);
     var textNodeMin = document.createElement('input');
     minCell.appendChild(textNodeMin);
     textNodeMin.size = 20;
     textNodeMin.name = "firsttext" + rowNumber;
     textNodeMin.id = "firsttext" + rowNumber;

     // cell 2
     var maxCell = row.insertCell(1);
     var textNodeMax = document.createElement('input');
     maxCell.appendChild(textNodeMax);
     textNodeMax.size = 20;
     textNodeMax.name = "secondtext" + rowNumber;
     textNodeMax.id = "secondtext" + rowNumber;
    
     // cell 3. Change this to select
     var incCell = row.insertCell(2);
     var textNodeInc = document.createElement('select');
     incCell.appendChild(textNodeInc);
  
     textNodeInc.name = "uitype" + rowNumber;     
     textNodeInc.id = "uitype" + rowNumber;
     
     textNodeInc.onchange = new Function("addmulval('uitype"+rowNumber+"')");
     for(j=0;j<count;j++)  
	 {
      	 var anOption = document.createElement("OPTION");
    	  textNodeInc.options.add(anOption);
    	  anOption.innerText = a[j];
    	  anOption.Value = a[j];
   // 	  textNodeInc.options[textNodeInc.options.length] = new Option(a[j], a[j]);

	 }
    var onch=document.getElementById("uitype" + rowNumber);
//    onch.onchange = "addmulval('uitype"+rowNumber+"');";
 
   onch.onchange = new Function("addmulval('uitype"+rowNumber+"')");
   
 //  onch.onchange=function(){addmulval('uitype2');};
  
     document.getElementById("rangeCount").value = parseInt(document.getElementById("rangeCount").value) + 1;  
}
 

  function addmulval(uitype)
  {
	  var optionvalue=document.getElementById(uitype);
	  if(uitype=="uitype1")
		  {
		  var selected=optionvalue.value;
		  }
	  else{
	  selected=optionvalue.options[optionvalue.selectedIndex].Value;
	  }
	  if(selected=="Selectbox"||selected=="Radiobutton")
	{
		
	  	var i=0;
	  	var reply = prompt("Enter the number of options", "");
	 
	  	var tbl = document.getElementById('multipleRangeTable');   // ID of table
	    var lastRow = tbl.rows.length;
	    
	    var rowNumber = lastRow + 1;
	    var row = tbl.insertRow(lastRow);  
	     
	     // cell 1
	     
	     var minCell = row.insertCell(0);
	     for(i=1;i<=reply;i++)
	 	{
	     	var textNodeMin = document.createElement('input');
	     	minCell.appendChild(textNodeMin);
	     	textNodeMin.size = 25;
	     	textNodeMin.name = rowNumber+"firsttext" + i;
	     	textNodeMin.id = rowNumber+"firsttext" + i;
	   
	    	 var nextline = document.createElement('br');
		     minCell.appendChild(nextline);
	 	}
	     var textNodeMin = document.createElement('input');
	     	minCell.appendChild(textNodeMin);
	     	textNodeMin.style.visibility="hidden";
	     	textNodeMin.name = uitype+"nor";
	     	textNodeMin.id = uitype+"nor";
	     	textNodeMin.value=reply;
	     	 document.getElementById("rangeCount").value = parseInt(document.getElementById("rangeCount").value) + 1;  
	     	 
	}
  }
  
 function resetfields()
  {
	 
	 var tbl = document.getElementById('multipleRangeTable');   // ID of table
	 var lastRow = tbl.rows.length;
    
     
     for(k=lastRow-1;k>0;k--)
   	 {
   		  tbl.deleteRow(k);
     }
     document.getElementById("rangeCount").value="1";

	 
  }
  

  
  function isNumber(data, type)
{    
	var numStr=type;
	var thisChar;
	var counter=0;
	for(var i=0; i < data.length; i++)
		{
			thisChar=data.substring(i,i+1);
			if(numStr.indexOf(thisChar)!=-1)
			{counter++;}
		}
		if(counter==data.length)
		{return true;}
		else
		return false;
 }
function validate()
{
	var sel=document.getElementById("rtype");
if(document.form1.rname.value =="")
   {
     alert("Enter Report Name.");
     document.form1.rname.select();
     return false;
   }
   if(isNumber(document.form1.rname.value, "abcdefghijklmnopqrstuvwxyz  ABCDEFGHIJKLMNOPQRSTUVWXYZ")!=true)
   {
       alert("Report Name field can accept alphabet only");
       document.form1.rname.select();
       return false;
   }
 if(document.form1.tfname.value =="")
   {
     alert("Enter your Template File Name.");
     document.form1.tfname.select();
     return false;
   }
   if(isNumber(document.form1.tfname.value, "abcdefghijklmnopqrstuvwxyz  ABCDEFGHIJKLMNOPQRSTUVWXYZ")!=true)
   {
       alert("Template File Name field can accept alphabet only");
       document.form1.tfname.select();
       return false;
   }
  if ( sel.selectedIndex == 0 ) 
	{ 
		alert ( "Please select Report Type." ); 
		return false;
	} 
  var nor=document.getElementById("rangeCount").value; 
  var fieldname="";
  for(k=1;k<=nor;k++)
	{
	  fieldname1="firsttext"+k;
	  fieldname2="secondtext"+k;
	  fieldname3="uitype"+k;
	  if(document.getElementById(fieldname1).value =="")
	   {	
		  alert ( "Please enter all text fields."+fieldname1 ); 
		  return false;
	   
	   }
	  else if(document.getElementById(fieldname2).value =="")
	  {	
		  alert ( "Please enter all text fields."+fieldname2 ); 
		  return false;
	   }
	  else if(document.getElementById(fieldname3).selectedIndex == 0)
		{
		  alert ( "Please select all uitype."+fieldname3 ); 
		  return false;
		 }
	  else if(document.getElementById(fieldname3).selectedIndex == 3||document.getElementById(fieldname3).selectedIndex == 4)
		  {
		  k=k+1;
		  	var nr=document.getElementById(fieldname3+"nor").value;
		  	for(var p=1;p<=nr;p++)
		  		{
		  			var m=k;
		  			var mfield=m+"firsttext"+p;
		  			if(document.getElementById(mfield).value =="")
		  				{alert ( "Please enter all option fields." ); 
		  				return false;}
		  		}
		  }
	}
  return true;
} 
  
  
 
  
  
</SCRIPT> 
<form id="form1" name="form1" method="post" action="adg.do?method=savetemplate" onSubmit="return validate()">
<%String f=(String)request.getAttribute("flag");
if(f=="1")
{%>
 <div align="center" id="msgLayer" class="msgstyle"><u><font color="red">template file name not found </font></u></div>
 <%}else if(f=="2"){%>
  <div align="center" id="msgLayer" class="msgstyle"><u><font color="red">report name already exists </font></u></div>
  <%} %>
 <table width="484" border="0" align="center" cellpadding="2" cellspacing="3">
  <tr>
    <td width="255" bgcolor="#FFFFFF" class="style1"><div align="right"> Report Name :</div></td>
    <td width="242" bgcolor="#FFFFFF"><div align="left">
      <input type="text" id="rname" name="rname" />*
    </div></td>
  </tr>
  <tr>
    <td bgcolor="#FFFFFF" class="style1"><div align="right">Report Type:</div></td>
    <td bgcolor="#FFFFFF">      <div align="left">
      <label for="select"></label>
    </div>
      <label for="select"></label>
      <div align="left"><select name="rtype" id="rtype">
      <option>---select---</option>
      <% 
	
		ResultSet rs1 = (ResultSet)request.getAttribute("resultset1");
		while(rs1.next())
		{
			String rtype=rs1.getString(1);

%>
			<option value="<%=rtype%>"><%=rtype%></option>
<%
		}
	
%>
		
      </select>*</div></td>
  </tr>
  <tr>
    <td bgcolor="#FFFFFF" class="style1"><div align="right">Template File Name:</div></td>
    <td bgcolor="#FFFFFF">      <div align="left">
      <input type="text" id="tfname" name="tfname" />*    
    </div></td>
  </tr>
</table>
<p>&nbsp;</p>
<table width="480" border="0" align="center" cellpadding="2" cellspacing="3">
    <tr>
      <td width="173" height="44" bgcolor="#FFFFFF" class="style1"><label for="textfield"></label>
      <div align="center"><label>Keyword</label></div></td>
      <td width="173" bgcolor="#FFFFFF" class="style1"><div align="center">
        <label for="textfield2"></label>
        <LABEL>Report Particular Type Name</LABEL>
      </div></td>
      <td width="171" bgcolor="#FFFFFF"><div align="center">
        <label for="select"></label>
        <label class="style1">UI Type</label>
      </div></td>
    </tr>
  </table>
<table id="multipleRangeTable" width="478" height="54" border="0" align="center" cellpadding="2" cellspacing="3">
  <tr>
    <td width="173" height="46"><input type="text" name="firsttext1" id="firsttext1"></td>
     <td width="174" height="46"><input type="text" name="secondtext1" id="secondtext1"></td>
       <td width="434" height="46"><select name="uitype1" id="uitype1" onChange="javascript:addmulval('uitype1');">
        <option>---select---</option>
        <% 
	
		ResultSet rs2 = (ResultSet)request.getAttribute("resultset2");
		while(rs2.next())
		{
			String rtype1=rs2.getString(1);

%>
        <option value="<%=rtype1%>"><%=rtype1%></option>
        <%
		}
	
%>
      </select>
      </td>
  
  </tr>
</table>
<table width="477" height="38" border="0" align="center" cellpadding="2" cellspacing="3">
  <tr>
          <td width="460" height="30"><input type="hidden" id="rangeCount" name="rangeCount" value="1"/><input type="button" name="button" id="button" class="button" value="ADD NEW" onClick="add()"></td>
          
    </tr>
  </table>
    <p>&nbsp;</p>
<div align="center">

  <input type="submit" name="Submit" class="button" value="Submit"/> 
  <input type="button" name="button2" id="button2" class="button" value="Reset"  onClick="resetfields()"/>
</div>
<p>&nbsp;</p>
<p>
 
</form>
<form id="linkform" name="linkform" method="post" action="">
 
</form>
<p>&nbsp;</p>
<!--webbot BOT="GeneratedScript" PREVIEW=" " startspan --><script Language="JavaScript" Type="text/javascript"><!--


//--></script><!--webbot BOT="GeneratedScript" endspan -->
</body>
</html>